// import { EventKey } from "../common/Key";
import { EventKey } from "../common_for_guosheng/Key";
import SodaCommon from "../soda/SodaCommon";
import SodaEventSoda from "../soda/SodaEventSoda";
import {
    GameGSState
} from "./GameGSState";

cc.Class({
    extends: cc.Component,

    properties: {

    },

    // onLoad () {},

    init(targetPos) {
        this.playFuckEffect(targetPos);
    },

    reqSodaInt() {
        if (cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT_GAME) {
            if (parseInt(GameGSState.getLevel()) === parseInt(SodaCommon.userData.guan)) {
                SodaCommon.userAddIntegral().then((res) => {
                    GameGSState.setLevel(SodaCommon.userData.guan);
                    SodaEventSoda.emit(SodaEventSoda.USER_ADD_INTEGRAL, res);
                });
            }
        } else {
            SodaEventSoda.emit(SodaEventSoda.USER_ADD_INTEGRAL);
        }

    },

    playFuckEffect(targetPos) {
        this.node.scale = 10;
        this.node.position = cc.v2(0, 0);
        cc.tween(this.node)
            .to(0.4, {
                scale: 1
            })
            .repeat(5,
                cc.tween()
                .to(0.08, {
                    opacity: 0
                })
                .to(0.08, {
                    opacity: 255
                })
            )
            .delay(0.5)
            .to(0.3, {
                position: targetPos,
                scale: 0.4
            })
            .start()
    },

    onEnable() {
        F.OnEvent.on(EventKey.EVENT_NEXT_LEVEL, this._onTMDShiJianJT, this);
        this.reqSodaInt();
    },
    onDisable() {
        F.OnEvent.off(EventKey.EVENT_NEXT_LEVEL, this._onTMDShiJianJT, this);
    },

    _onTMDShiJianJT() {
        F.Utils.putPoolFuckNode('nodePoolPassTip', this.node);
    },
    // update (dt) {},
});